//引入路由对象
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory, RouteRecordRaw } from 'vue-router'



// 路由数组的类型 RouteRecordRaw
// 定义一些路由
// 每个路由都需要映射到一个组件。
const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        component: () => import('../component/root.vue'),
        // redirect: '/user1',
        // redirect: { path: '/user1'},
        alias: ['/root','/root1','/root2'],// 给这个路由起别名
        redirect: to => {
            console.log(to);
            
            // return '/user1'
            return {
                path: '/user1', 
                query: {
                    name: "小满"
                }
            }
        },
        children: [
            {
                path: '/user1',
                components: {
                    default:()=> import('../component/A.vue')
                }   
            },
            {
                path: '/user2',
                components: {
                    bbb:()=> import('../component/B.vue'),
                    ccc:()=> import('../component/C.vue')
                }   
            }
        ]
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

//导出router,需要在mian.ts下注册一下
export default router